<template>
    <el-dialog :title="titleMap[mode]" v-model="visible" :width="1500" destroy-on-close :close-on-click-modal="false" align-center @closed="$emit('closed')">
        <el-header>
            <div class="right-panel">
                <div class="right-panel-search">
                    <el-input v-model="search.search_keyword" placeholder="条码" clearable @keyup.enter="upsearch"></el-input>
                    <el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
                    <el-button type="primary" icon="el-icon-refresh" @click="refresh"></el-button>
                    <el-button @click="uncomplete" v-auth="'waresend.complete'">撤销作废</el-button>
                </div>
            </div>
        </el-header>
        <el-main class="nopadding">
            <scTable ref="table" :apiObj="apiObj" row-key="id" @selection-change="selectionChange" border height="550" :params="{is_use: 2}" :pageSize="1000">
                <el-table-column width="1"></el-table-column>
                <el-table-column type="selection" width="50" align="center"></el-table-column>
                <el-table-column label="发货单号" prop="purchasesend.send_code" align="center"></el-table-column>
                <el-table-column label="条码" prop="roll_code" align="center"></el-table-column>
                <el-table-column label="品名" prop="goods_name" align="center"></el-table-column>
                <el-table-column label="颜色" prop="color" align="center"></el-table-column>
                <el-table-column label="花型" prop="flower" align="center"></el-table-column>
                <el-table-column label="供应商" prop="apply_name" align="center"></el-table-column>
                <el-table-column label="净重" prop="net_weight" align="center"></el-table-column>
                <el-table-column label="米数" prop="meter" align="center"></el-table-column>
                <el-table-column label="码数" prop="code_number" align="center"></el-table-column>
                <el-table-column label="克重" prop="gram_weight" align="center"></el-table-column>
            </scTable>
        </el-main>
        <template #footer>
			<el-button @click="visible = false">取 消</el-button>
			<!-- <el-button v-if="mode != 'show'" type="primary" :loading="isSaveing" @click="submit(0)">保存</el-button> -->
        </template>
    </el-dialog>
</template>

<script>

export default {
    props: {
        query: {type: Object, default: () => ({})},
    },
    emits: ['success', 'closed'],
    data() {
        return {
            mode: "add",
            titleMap: {
                add: '新增发货单',
                edit: '作废记录',
                show: '查看发货单',
            },
            visible: false,
            isSaveing: false,
            total_stock: {},
            search: {
                search_keyword: "",
                search_field: "roll_code",
                received_date: 1
            },
            id: "",
            apiObj: this.$API.ware.ware.send.cancel.list,
            ware_number: 0,
            can_ware_number: 0,
            selection: [],
        }
    },
    mounted() {
    },
    methods: {
        //显示
        open(mode = 'add') {
            this.mode = mode;
            this.visible = true;
            return this
        },
        //表单注入数据
        async setData(data) {
            this.id = data.id
            this.ware_number = data.ware_number
            this.can_ware_number = Number(data.total_count) - Number(data.ware_number)
        },
        //表格选择后回调事件
        selectionChange(selection) {
            this.selection = selection;
        },
        upsearch(){
            this.$refs.table.upData(this.search)
        },
        refresh(){
            for (const key in this.search) {
                this.search[key] = null;
            }
            this.search.search_field = "roll_code",
            this.search.received_date = 1,
            this.$refs.table.upData(this.search)
        },
        uncomplete(){
            var roll_codes = [];
            this.selection.forEach((item) => {
                roll_codes.push(item.roll_code)
            })
            this.$confirm(`确定批量撤销作废选中的 ${this.selection.length} 项吗？`, '提示', {
                type: 'warning'
            }).then(async() => {
                var reqData = { roll_codes: roll_codes }
                var res = await this.$API.ware.ware.send.cancel.delete.post(reqData);
                if (res.code == 1) {
                    this.$refs.table.refresh()
                    this.$message.success("操作成功")
                } else {
                    this.$alert(res.message, "提示", { type: 'error' })
                }
            }).catch(() => {})
        },
    }
}
</script>

<style lang="scss" scoped>
.flex{
    display: flex;
    justify-content: space-between;
}
</style>
